package rsschart.charter;

public class CharterUtil {
	
	public static String clickNote() {
		return "<text x=\"5\" y=\"8\" text-anchor=\"start\" font-size=\"6\">Click a chart element...</text>\n";
	}

	public static String getHeader(int w, int h) {
		StringBuilder str = new StringBuilder();
		str.append("<?xml version=\"1.0\" standalone=\"no\"?>");
		str.append("\n");
		str.append("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" " +
				"\n"+
				"\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
		str.append("<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" " +
				"xmlns:xlink=\"http://www.w3.org/1999/xlink\" " +
				"width=\"" + w + " px\"  height=\"" + h + "px\" viewBox=\"0 0 320 240\">\n");

		return str.toString();
	}
	
	public static String getClose() {
		return "\n</svg>";
	}

	//-- font size fixed at 11 point:
	public static String getTitle(int x, int y, String title) {
		StringBuilder str = new StringBuilder();
		str.append("<text x=\""+ x + "\" y=\"" + y + "\"");
		str.append(" text-anchor=\"middle\" font-size=\"11\">" + title + "</text>\n");
		return str.toString();
	}
	
	public static String getChartFrame(int x, int y, int width, int height) {
		String frame;
		frame = "<rect x=\"" + x + "\" y=\"" + y + "\" width=\"" + width +
				"\" style=\"fill:url(#background-grad)\"" +
				" height=\"" + height + "\" fill=\"none\" stroke=\"black\" stroke-width=\"0.25\"/>\n";
		return frame;
	}

	
	public static String getClickMethod() {
		StringBuffer method = new StringBuffer();
		
		method.append("<script type=\"text/javascript\">\n");
		method.append("<![CDATA[\n");
		method.append("function doLink(rssLink, catg, catgVal, dataSet, dataSetVal, val) {\n");
		method.append("    var e_catg = escape(catg);\n");
		method.append("    var e_catgVal = escape(catgVal);\n");
		method.append("    var e_dataSet = escape(dataSet);\n");
		method.append("    var e_dataSetVal = escape(dataSetVal);\n");
		method.append("    var e_val = escape(val);\n");
		method.append("    var fullLink = rssLink + \"?catg=\" + e_catg + \"&catgVal=\" + e_catgVal + ");
		method.append("\"&dataSet=\" + e_dataSet + \"&dataSetVal=\" + e_dataSetVal + \"&val=\" + e_val;\n");
		method.append("    var w = window.open();\n");
		method.append("    w.document.location=fullLink;\n");
		method.append("}\n");
		method.append("//]]>\n");
		method.append("</script>\n");
		
		return method.toString();

	}


	public static String getDoLink(String methodName, String url, String catg, String catgVal, 
								   String dataSet, String dataSetVal, String val) {
		String str;
		
		str = methodName + "(\"" + url + "\",\"" + catg + "\",\"" + catgVal + "\",\"" + dataSet + 
			  "\",\"" + dataSetVal + "\",\"" + val + "\")";
		return str;
		
	}
	
	
	
}
